package gatperdut.chato.core.item;

import gatperdut.chato.model.Chato.Item.Amount;

public abstract class AmountController {

    private final Amount amount;

    public AmountController( Amount amount ) {
        this.amount = amount;
    }

    public int getWhatsLeftToMax() {
        return getAmount().getMax() - getAmount().getCurrent();
    }

    public void setToMax() {
        setCurrent( getMax() );
    }

    public void increase( int amount ) {
        setCurrent( getCurrent() + amount );
    }

    public void decrease( int amount ) {
        setCurrent( getCurrent() - amount );
    }

    public boolean canAffordIncrease( int increase ) {
        return getCurrent() + increase <= getMax();
    }

    public boolean canAffordDecrease( int decrease ) {
        return ( getCurrent() - decrease ) >= 0;
    }

    public void setCurrent( int current ) {
        getAmount().setCurrent( current );
    }

    public int getCurrent() {
        return getAmount().getCurrent();
    }

    public void setMax( int max ) {
        getAmount().setMax( max );
    }

    public int getMax() {
        return getAmount().getMax();
    }

    public Amount getAmount() {
        return amount;
    }

    public boolean isEmpty() {
        return getAmount().getCurrent() == 0;
    }

}
